<template>
	<view class="mainpadding2">
		<u-navbar title="儲值管理" placeholder autoBack>
			<view class="flexright xiaohui" slot="right" @click="jumpurl('/pages/workbench/tianjiaczxx')">添加</view>
		</u-navbar>
		<view class="ffffff mainpadding_top radius" v-for="item in list" :key="item.id">
			<view class="xiaohei titletext bold">{{item.name}}</view>
			<view class="hui_text margin_top bold">充<text class="xiaohong">{{item.price}}</text>送<text class="xiaohong">{{item.send_price}}</text></view>
			<view class="margin_top hui_text smalltext bold">使用時間<text class="hong_text">{{item.start_time_text}}~{{item.end_time_text}}</text></view>
			<view class="flexright margin_top hei_text main_size bold">
				<view class="flexleft" @click="jumpdetail('/pages/workbench/tianjiaczxx?id=',item.id)">
					<u-icon name="edit-pen" color="#999" size="16"></u-icon>
					<view class="xiaohei">編輯</view>
				</view>
				<view class="flexleft margin_left" @click="delitem(item)">
					<u-icon name="trash" color="#999" size="16"></u-icon>
					<view class="xiaohei">刪除</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[]
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			delitem(item) {
				this.http.modal('提示', '確認刪除當前數據嗎？', true, (res) => {
					if (res) {
						this.http.request("/api/shop/delRechargeItem", 'POST', {
							id: item.id
						}).then(res=>{
							if (res.code == 1) {
								this.http.toast("刪除成功")
								this.init()
							} else{
								this.http.toast(res.msg);
							}
						})
						
					}
				})
			},
			init() {
				this.http.request("/api/shop/rechargeItemIndex", 'POST', {
					shop_id: uni.getStorageSync("shop_id")
				}).then(res=>{
					if (res.code == 1) {
						this.list = res.data
					} else {
						this.http.toast(res.msg);
					}
				})
			},
		}
	}
</script>

<style>

</style>
